package 线程.day2.demo1;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Test1 {
    public static void main(String[] args) {
        ExecutorService pool= Executors.newFixedThreadPool(3);
        pool= Executors.newCachedThreadPool();
        pool=Executors.newSingleThreadExecutor();
        for(int i=0;i<10;i++){
            pool.submit(new B());
        }
        //pool.shutdown();//会把队列中任务也一起执行完后才关闭池子
        //pool.shutdownNow();//只会把当前正在执行的任务完成，队列中不执行，就关闭池子。
    }
}

class B implements Runnable{
    int i=0;
    @Override
    public void run() {
        System.out.println("i="+i++);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {

        }
    }
}
